package cliente;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class VentanaCliente extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel contentPane;
	private JTextField textFieldUsuario;
	private JPasswordField textFieldContrasena;
	private JTextField textFieldIP;
	private JButton btnNewButton;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		VentanaCliente v = new VentanaCliente();
		v.setEnabled(true);
		
	}

	/**
	 * Create the frame.
	 */
	public VentanaCliente() {
		setTitle(".:: Sistema Seguridad: Login ::.");
		
		setBounds(100, 100, 419, 269);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNombreDeUsuario = new JLabel("Nombre de Usuario");
		lblNombreDeUsuario.setHorizontalAlignment(SwingConstants.CENTER);
		lblNombreDeUsuario.setFont(new Font("Times New Roman", Font.BOLD, 12));
		lblNombreDeUsuario.setBounds(35, 28, 114, 29);
		contentPane.add(lblNombreDeUsuario);
		
		textFieldUsuario = new JTextField();
		textFieldUsuario.setBounds(159, 28, 168, 28);
		contentPane.add(textFieldUsuario);
		textFieldUsuario.setColumns(10);
		
		JLabel lblContrasea = new JLabel("Contrase\u00F1a");
		lblContrasea.setHorizontalAlignment(SwingConstants.CENTER);
		lblContrasea.setFont(new Font("Times New Roman", Font.BOLD, 12));
		lblContrasea.setBounds(35, 68, 114, 28);
		contentPane.add(lblContrasea);
		
		textFieldContrasena = new JPasswordField();
		textFieldContrasena.setBounds(159, 67, 168, 29);
		contentPane.add(textFieldContrasena);
		textFieldContrasena.setColumns(10);
		
		JLabel lblDireccinIp = new JLabel("Direcci\u00F3n IP");
		lblDireccinIp.setHorizontalAlignment(SwingConstants.CENTER);
		lblDireccinIp.setFont(new Font("Times New Roman", Font.BOLD, 12));
		lblDireccinIp.setBounds(35, 107, 114, 28);
		contentPane.add(lblDireccinIp);
		
		textFieldIP = new JTextField();
		textFieldIP.setBounds(159, 107, 168, 29);
		contentPane.add(textFieldIP);
		textFieldIP.setColumns(10);
		textFieldIP.setText("127.0.0.1");
		
		btnNewButton = new JButton("Conectar");
		btnNewButton.addActionListener(this);
		btnNewButton.setFont(new Font("Times New Roman", Font.BOLD, 12));
		
	
		btnNewButton.setBounds(92, 170, 114, 29);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("Borrar");
		btnNewButton_1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				textFieldUsuario.setText("");
				textFieldContrasena.setText("");
				
			}
		});
		btnNewButton_1.setFont(new Font("Times New Roman", Font.BOLD, 12));
		btnNewButton_1.setBounds(220, 170, 107, 29);
		contentPane.add(btnNewButton_1);
		
		setLocationRelativeTo(null);
		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void vaciarContrasenaField() {
		textFieldContrasena.setText("");
	}

	public void vaciarUsuario() {
		textFieldUsuario.setText("");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

		// Pulsar el boton validar
		if (arg0.getSource() == btnNewButton) {
			
			GestorInicioSesion gis = new GestorInicioSesion(textFieldUsuario.getText(), textFieldContrasena.getText(),
					textFieldIP.getText(), this);
			gis.inicioConexion();
			//this.dispose();
		}
	}
	
	
	
}
